package com.shanghaiyimu.yimiyangche.adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shanghaiyimu.yimiyangche.R;
import com.shanghaiyimu.yimiyangche.activity.DianpuContentActivity;
import com.shanghaiyimu.yimiyangche.bean.DianPuBean;

import java.util.List;

/**
 * Created by Administrator on 2017/7/6.
 */

public class DianPuPTRAdapter extends BaseAdapter {

    private Context context;
    private List<DianPuBean> list;

    public DianPuPTRAdapter(Context context, List<DianPuBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list!=null?list.size():0;
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        DianPuBean dianPuBean = null;
        if (view == null){
            view = LayoutInflater.from(context).inflate(R.layout.dianpu_ptrlv_item,viewGroup,false);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }else {
            holder = (ViewHolder) view.getTag();
        }
        dianPuBean = list.get(i);
        holder.name.setText(dianPuBean.getName());
        holder.address.setText(dianPuBean.getAddress());

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context,DianpuContentActivity.class);
                context.startActivity(intent);
            }
        });

        return view;
    }
    static class ViewHolder{
        TextView name,address;
        public ViewHolder(View view) {

            name = (TextView) view.findViewById(R.id.dianpu_name);
            address = (TextView) view.findViewById(R.id.dianpu_address);



        }
    }
}
